package create;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.border.EmptyBorder;

import database.Password;
import login.login;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import util.MD5;
public class PwdInfo extends JFrame {
	Password p = new Password();
	private JPanel contentPane;
	private JPasswordField pwd;
	private JPasswordField pwdAgain;
	private static int flag = 0;
	private static int user;
	private String ep;// encryptionPassword 准备加密的字符串
	/**
	 * Launch the application.
	 */
//	public static void main(String[] args) {
//		EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				try {
//					PwdInfo frame = new PwdInfo(flag);
//					frame.setVisible(true);
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		});
//	}

	/**
	 * Create the frame.
	 */
	public PwdInfo(int flag,int user) {
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		this.flag = flag;
		this.user = user;
		
		JLabel lblNewLabel = new JLabel("密码设置");
		lblNewLabel.setFont(new Font("Lucida Grande", Font.PLAIN, 17));
		lblNewLabel.setBounds(190, 19, 84, 30);
		contentPane.add(lblNewLabel);
		
		JLabel label = new JLabel("请输入密码");
		label.setBounds(71, 88, 76, 23);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("请再次输入密码");
		label_1.setBounds(71, 145, 91, 23);
		contentPane.add(label_1);
		
		pwd = new JPasswordField();
		pwd.setBounds(239, 86, 130, 26);
		contentPane.add(pwd);
		pwd.setColumns(10);
		
		pwdAgain = new JPasswordField();
		pwdAgain.setColumns(10);
		pwdAgain.setBounds(239, 143, 130, 26);
		contentPane.add(pwdAgain);
		
		JButton push = new JButton("提交");
		push.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(!pwd.getText().equals(pwdAgain.getText())){
					JOptionPane.showMessageDialog(null,"密码输入不一致","信息提示框",JOptionPane.INFORMATION_MESSAGE);
				}else{
					if(flag == 1){
						ep = pwd.getText();
						String s = MD5.getMD5(ep);
						p.setStupwd(s);
						p.setStuuser(user);
					}else if(flag == 2){
						ep = pwd.getText();
						String s = MD5.getMD5(ep);
						p.setTeapwd(s);
						p.setTeauser(user);
					}
					new Create().InputPwd(p);
					JOptionPane.showMessageDialog(null,"创建成功","信息提示框",JOptionPane.INFORMATION_MESSAGE);
					new login();
					setVisible(false);
				}
			}
		});
		push.setBounds(325, 212, 84, 29);
		contentPane.add(push);
		
		JButton clear = new JButton("清空");
		clear.setBounds(190, 212, 84, 29);
		contentPane.add(clear);
	}
}
